package com.dq.ad;

import com.hx.currency.HXCurrencySDK;
import com.qq.e.o.data.HttpUtil;
import com.qq.e.o.data.model.AdLogInfo;
import com.qq.e.o.utils.ILog;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * FileName: ADUtils
 * Author: admin
 * Date: 2021/12/23 13:18
 * Description:
 */
public class ADUtils {
    public static boolean canShowVideoAd;

    public interface AdLogListener {
        void onSuccess();
    }

    public static void sendAdLog(final AdLogInfo adInfo) {
        sendAdLog(adInfo, null);
    }

    public static void sendAdLog(final AdLogInfo adInfo, final AdLogListener adLogListener) {
        ILog.e("开始上传广告日志：" + adInfo.toString());
        HXCurrencySDK.getInstance().sendAppAdLog(adInfo.getSdkType(),
                adInfo.getAdPosType(),
                adInfo.getAdPosId(),
                adInfo.getEcpm(),
                adInfo.getAction(),
                adInfo.getHasLegal(),
                adInfo.getOrderId(),
                adInfo.getErrCode(),
                adInfo.getRequestId(),
                new HttpUtil.HttpUtilCallback() {
                    @Override
                    public void onSuccess(int i, String s) {
                        if (adInfo.getAction() == 2 && adInfo.getAdPosType() == 5) {
                            try {
                                JSONObject jsonObject = new JSONObject(s);
                                int ad = jsonObject.optInt("va");
                                canShowVideoAd = ad == 0;
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                        if (adLogListener != null) {
                            adLogListener.onSuccess();
                        }
                        ILog.e("广告日志行为上报成功：" + s);
                    }

                    @Override
                    public void onFailed(int i, Throwable throwable) {
                        ILog.e("广告日志行为上报异常：" + throwable.getMessage());
                    }
                });
    }

//    public static void getToken(){
//        ILog.e("开始获取token");
//        HXCurrencySDK.getInstance().getQaToken(new HttpUtil.HttpUtilCallback() {
//            @Override
//            public void onSuccess(int i, String s) {
//                ILog.e("获取token成功：" + s);
//            }
//
//            @Override
//            public void onFailed(int i, Throwable throwable) {
//                ILog.e("获取token失败：" + throwable.getMessage());
//            }
//        });
//    }
}